import { isArray } from 'lodash';

import { checkIsSupplier } from '@/utils/utils';

/**
 * 获取供应商显示的组织列表
 * @param dataSource
 * @returns
 */
export function getShowDataSource(dataSource: any[] = []) {
  const isSupplier = checkIsSupplier();
  if (isSupplier) {
    const root = dataSource.find((item) => item.orgType === 'PARTNERS');

    return root?.children || [];
  }

  return dataSource;
}

export function recursionTreeData(list: any, parent?: any) {
  if (!isArray(list)) {
    return;
  }
  list.forEach((item: any) => {
    if (item.parentOrgId === 'ROOT') {
      item.level = 1;
    } else {
      item.level = parent ? parent.level + 1 : 1;
    }
    item.disabled = item.level < 3;
    if (item.children) {
      recursionTreeData(item.children, item);
    }
  });
}
